package com.example.hotel_lxy.ui.activity;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.CountDownTimer;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.hotel_lxy.R;
import com.example.hotel_lxy.application.ARouterPath;
import com.example.hotel_lxy.ui.dialog.WebDialog;
import com.example.hotel_lxy.utils.SPUtils;
import com.ysxsoft.common_base.base.BaseActivity;

/**
 *
 * 欢迎页
 * **/
@Route(path = "/main/WelcomeActivity")
public class WelcomeActivity extends BaseActivity {
    CountDownTimer timer;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_welcome;
    }
    public static void start() {
        ARouter.getInstance().build(ARouterPath.getWelcomeActivity())
                .navigation();
    }
    @Override
    public void doWork() {
        super.doWork();
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        timer = new CountDownTimer(3 * 1000, 1000) {
            //进行时
            public void onTick(long millisUntilFinished) {

            }
            //结束
            public void onFinish() {
                LoginActivity.start();
                finish();
            }
        };
        String webDialog = SPUtils.get(WelcomeActivity.this, "WebDialog", "").toString();
        if(webDialog.equals("")){
            WebDialog.show(WelcomeActivity.this,null).setListener(new WebDialog.OnDialogClickListener() {
                @Override
                public void onPositiveClick(String s) {
                    if(s.equals("2")){
                        SPUtils.put(WelcomeActivity.this, "WebDialog", "2");
                        timer.start();
                    }else{
                        backToActivity();
                    }
                }
            });
        }else{
            timer.start();
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
    }
}